﻿ 
using STSdb4.Database;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using UserCenter.Console.Sdk.Demo.Core;

namespace UserCenter.Console.Sdk.Demo.Tools
{
    public static class DbHelper
    {
        static string codeBase = Assembly.GetCallingAssembly().CodeBase;


        readonly static string dbPath;

        readonly static IStorageEngine database;

        static DbHelper()
        {
            string dbDir = "../../../..";
            dbPath = Path.Combine(Path.Combine(new Uri(codeBase).LocalPath, dbDir), "demo.db");
            database = STSdb.FromFile(dbPath);
        }


        

        public static TableInfo<T> GetTable<T>()
        { 
            var table = database.OpenXTable<Guid, T>(typeof(T).Name);
            return new TableInfo<T>(database, table);
        }






    }
}
